<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users_take_log', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger("user_id")->comment("用户id");
            $table->unsignedBigInteger("loan_id")->comment("物料id");
            $table->unsignedBigInteger("price_ticket")->default(0)->comment("价格：次数");
            $table->decimal('price_money', 12)->default(0)->comment("价格： 金额");
            $table->timestamps();
            $table->index("user_id");
        });
        DB::statement("ALTER TABLE `users_take_log` COMMENT='用户抢单流水日志'");

        Schema::table('loan_application', function (Blueprint $table) {
            $table->unsignedInteger('price_ticket')->default(1)->comment("抢单价格：次数")->after('status');
            $table->decimal('price_money', 12)->default(0)->comment("抢单价格： 金额")->after('status');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users_take_log');

        Schema::table('loan_application', function (Blueprint $table) {
            $table->dropColumn(['price_ticket']);
        });
    }
};
